package com.ny.mapper;
import com.ny.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UserMapper {
    @Select("select  * from user ")
    public List<User> findAllUser();
    // 登录
    @Select("select * from user where username=#{username}")
    public User login(@Param("username") String username);
    // 根据用户名查询用户
    @Select("select * from user where username=#{username}")
    public User findUserByUsername(@Param("username") String username);
    
    // 根据邮箱查询用户
    @Select("select * from user where email=#{email}")
    public User findUserByEmail(@Param("email") String email);
    
    // 更新用户密码
    @Update("update user set password=#{password} where user_id=#{userId}")
    public int updatePassword(@Param("userId") int userId, @Param("password") String password);
    
    // 更新用户邮箱
    @Update("update user set email=#{email} where user_id=#{userId}")
    public int updateEmail(@Param("userId") int userId, @Param("email") String email);
    // 注册功能:密码加密
    @Insert("INSERT INTO `user` (username, password, nickname, phone, email, is_active, created_time) " +
            "VALUES (#{username}, #{password}, #{nickname}, #{phone}, #{email}, #{isActive}, #{createdTime})")
    @Options(useGeneratedKeys = true, keyProperty = "userId", keyColumn = "user_id")
    int registerUser(User user);


    @Insert("INSERT INTO `user` (username, password, nickname, phone, email, is_active, created_time) " +
            "VALUES (#{username}, #{password}, #{nickname}, #{phone}, #{email}, #{isActive}, #{createdTime})")
    @Options(useGeneratedKeys = true, keyProperty = "userId", keyColumn = "user_id")
    int insertUser(User user);
}
